<template>
  <div>
    <el-dialog
      v-model="dialogVisibleInner"
      title="选择表单"
      width="35%"
      :before-close="handleClose"
    >
      <el-form :model="formData" inline>
        <el-form-item>
          <el-input
            v-model="formData.documentName"
            placeholder="请输入单据名称"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :icon="useRenderIcon(Search)"
            >搜索</el-button
          >
        </el-form-item>
      </el-form>
      <el-transfer v-model="chosen" :data="allData" />
      <template #footer style="text-align: center">
        <span class="dialog-footer">
          <el-button @click="dialogVisibleInner = false">取消</el-button>
          <el-button type="primary" @click="dialogVisibleInner = false">
            确认
          </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from "vue";
import { ElMessageBox } from "element-plus";
import Search from "@iconify-icons/ep/search";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";

interface Option {
  key: number;
  label: string;
  disabled: boolean;
}

const dialogVisibleInner = ref(false);
const formData = reactive({
  documentName: ""
});

const handleClose = (done: () => void) => {
  ElMessageBox.confirm("Are you sure to close this dialog?")
    .then(() => {
      done();
    })
    .catch(() => {
      // catch error
    });
};
const generateData = () => {
  const data: Option[] = [];
  for (let i = 1; i <= 15; i++) {
    data.push({
      key: i,
      label: `Option ${i}`,
      disabled: i % 4 === 0
    });
  }
  return data;
};

const allData = ref<Option[]>(generateData());
const chosen = ref([]);

defineExpose({
  dialogVisibleInner
});
</script>

<style scoped>
.dialog-footer button:first-child {
  margin-right: 10px;
}
</style>
